<template>
<RouterLink to="/AddInvestInfo" style="margin-right: 10px;" >添加投资</RouterLink>

<RouterLink to="/AddFinan" style="margin-right: 10px;" >添加理财</RouterLink>
<RouterLink to="/ShowFinan" style="margin-right: 10px;" >显示理财</RouterLink>

<RouterLink to="/AddBorrow" style="margin-right: 10px;" >添加借款</RouterLink>
<RouterLink to="/ShowBorrow" style="margin-right: 10px;" >显示借款</RouterLink>

    <h1 style="text-align: center;" >投资项目列表</h1>
    <InvestInfoContent v-slot="info" >

        <input type="button" value="删除" class="btn btn-primary" @click="DelData(info.id)" />
        <a href="#" @click="Jump(info.id)">修改</a>

    </InvestInfoContent>
</template>
                                                                                                                                   
<script setup lang="ts">
import axios from 'axios';
import { useRouter } from 'vue-router';
import InvestInfoContent from './InvestInfoContent.vue'

const router = useRouter();

//删除方法
const DelData = (Id:string)=>{
    
    if(confirm("确定要删除吗?"))
    {
        axios({
        method:'get',
        url:'http://localhost:63517/api/Invest/DelDate',
        params:{
            Id:Id
        }
    })
    .then(res=>{
        if(res.data>0){
            alert('删除成功');
            ShowInvestInfo();
        }
        else if(res.data==-1){
            alert('有人投资,无法删除');
            return;
        }
        else{
            alert('删除失败');
            return;
        }
    })
    .catch(err=>{
        console.log(err);
    })
    }

}
//跳转到修改页面
const Jump =(Id:string)=>{
    router.push({
        name:'EditInvestInfo',
        params:{
            Id:Id
        }
    })
}

</script>